package com.central.dataManage.service;

import com.central.common.enums.PrivilegeType;
import com.central.common.model.Result;
import com.central.common.model.SysUser;
import com.central.common.model.TableInfo;
import com.central.common.service.ISuperService;
import com.central.dataManage.model.*;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;

/**
 * @author Tindy
 * @date 2021/7/5
 * @describe
 */
public interface ITableService extends ISuperService<TableInfo> {

    void delByDatasourceId(Long datasourceId);

    SysUser findTableOwner(Long datasourceId, String dbName, String tableName);

    void updateTableOwner(Long datasourceId, String dbName, String tableName, Long userId);

    String findTablePreview(Long datasourceId, String dbName, String tableName);

    Result dropTable(Long tableId, String reason);

    Result createTable(CreateTableEntity createTableEntity);

    Boolean synchTable(Long tableId) throws SQLException;

    void delByDatabaseId(Long databaseId);

    TableInfo findTableDetail(SysUser user, Long tableId);

    Result<List<ProjectPrivileges>> findProjectPrivileges(Long tableId);

    Result addProjectPrivileges(Long tableId, Long proId, List<PrivilegeType> privileges) throws SQLException;

    Result<List<UserPrivileges>> findUserPrivileges(Long proId, Long tableId);

    Result addUserPrivileges(SysUser gdbUser, Long userId, Long tableId, List<PrivilegeType> privileges) throws SQLException, ExecutionException, InterruptedException;

    Result<String> format(Long datasourceId, String sql);

    Result modifyTable(ModifyTableEntity modifyTableEntity) throws ExecutionException, InterruptedException;

    List<String> findDataTypes(Long databaseId);

    Map<String, List<PrivilegeType>> getAllTablePrivilege(Long datasourceId, Long proId, Long userId, Set<String> tables);

    TableInfo getTableInfo(Long datasourceId, String dbName, String tableName);
}